package cn.hanna.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author smileha
 * @create 2021-10-19 0:00
 * @description
 */
@Configuration
public class GatewayConfig {

    @Bean
    public RouteLocator myRouteLocator1(RouteLocatorBuilder builder){
        RouteLocatorBuilder.Builder routes = builder.routes();
        //http://news.baidu.com/finance
        routes.route("gateway_route1",r -> r.path("/finance")
                                                .uri("http://news.baidu.com/finance")).build();
        return routes.build();
    }

    @Bean
    public RouteLocator myRouteLocator2(RouteLocatorBuilder builder){
        RouteLocatorBuilder.Builder routes = builder.routes();
        //http://news.baidu.com/guonei
        routes.route("gateway_route1",r -> r.path("/guonei")
                .uri("http://news.baidu.com/guonei")).build();
        return routes.build();
    }
}
